import Http from "../utils/Http"
import url from "../utils/url"
import cache from "../utils/Cache"
// const http = new Http;
class Model extends Http{
    // 用户授权记录
    setUserInfo(data){
        // 返回promise对象
        return this.httpRequest({
            url:url.setuserinfo,
            data,
            method:"POST"
        })
    }
    getUserInfo(){
        return this.httpRequest({
            url:url.renting + "/" + cache.get("id")
        })
    }
    updateUserInfo(data){
        return this.httpRequest({
            url:url.renting,
            data:{ id:cache.get("id"),...data },
            method:"POST"
        })
    }
    upfile(obj){
        wx.chooseImage({
          // 可以上传3张图片
          count:3,
          // 原图和压缩
          sizeType:["original","compressed"],
          // 相机或图册
          sourceType:["album","camera"],
          success:(res) =>{
            let imgList = res.tempFilePaths;
            obj.setData({
              userinfo:{...obj.data.userinfo,imgList:imgList}
             });
            // console.log(imgList);
            // 循环
            imgList.forEach(filePath => {
              this.uploadFile({
                url: url.rentingUpfile, //仅为示例，非真实的接口地址
                filePath,
              }).then(res=>{
                  let json = JSON.parse(res.data);
                  // 字符串拼接
                  let card_img = obj.data.userinfo.card_img + "#" + json.pic;
                  // console.log(card_img);
                  obj.setData({
                    userinfo:{...obj.data.userinfo,card_img}
                  })
                  //do something
                })
            })
            
          }
        })
      }
}
export default new Model;